#
#  wd.switch_to.frame(name/id/webElement元素)
#  wd.switch_to.default_content()
#  wd.switch_to.window()
#  wd.switch_to.alert.accept()
#  wd.window_handles  wd.title  wd.current_window_handles


from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from changliang import LUJING
import time

wd = webdriver.Chrome(service=Service(LUJING))
wd.implicitly_wait(3)

wd.get('https://www.byhy.net/cdn2/files/selenium/sample2.html')

wd.switch_to.frame('innerFrame')
wd.find_element(By.CSS_SELECTOR,'#searchtext').send_keys('nihao')

wd.switch_to.default_content()
wd.find_element(By.CSS_SELECTOR,'#outerbutton').click()



wd.get('https://www.byhy.net/cdn2/files/selenium/sample3.html')

# 点击打开新窗口的链接
link = wd.find_element(By.TAG_NAME, "a")
link.click()

# wd.title属性是当前窗口的标题栏 文本
print(wd.title)
print(wd.window_handles)
main_window = wd.current_window_handle
for i in wd.window_handles:
    wd.switch_to.window(i)
    if wd.title == 'Bing':
        break
wd.find_element(By.CSS_SELECTOR,'#sb_form_q').send_keys('北京时间')
time.sleep(3)
wd.switch_to.window(main_window)
time.sleep(1)